<template>
  <div class="selectCc">
    <!-- 添加爱车头部 -->
    <CarHeader></CarHeader>
    <!-- 添加爱车标题 -->
    <div class="addCarTitle">
      <img :src="currentCarInfo.url" alt />
      <span>{{currentCarInfo.name}}-{{currentCarInfo.carCc}}</span>
    </div>
    <p class="addCarAction">
      {{currentCarInfo.displacement}}
      <span>></span>
    </p>
    <!-- 选择发动机排量提示 -->
    <p class="addCarSubtitle">请选择年份</p>
    <div class="addCar-list">
      <p
        v-for="(item,key) in currentCarInfo.displacements[currentCarInfo.displacement]"
        :key="key"
        @click="toAddCarId(item)"
      >{{item}}</p>
    </div>
  </div>
</template>

<script>
import CarHeader from "./CarHeader.vue";
import { mapState, mapMutations } from "vuex";
export default {
  computed: {
    ...mapState({
      currentCarInfo: "carInfo"
    }),
    ...mapState({
      currentCarDisplacement: "carDisplacement"
    })
  },
  components: {
    CarHeader
  },
  methods: {
    toAddCarId(item) {
      this.$store.commit("getAddCarYear", item);
      this.$router.push("/home/addCar/carSelectCc/carSelectYear/addCarId");
      this.$store.commit("clearChangeCarInfo");
    }
  }
};
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.selectCc {
  display: flex;
  flex-direction: column;
  //min-height: 100vh; //结合flex  和 下边区域的flex 一起使用，让.addCar-list 自适应剩余高度
  height: 100%;
  //overflow: hidden;
  .addCarTitle {
    height: 45px;
    line-height: 45px;
    background-color: #a1171b;
    border-top: 1px solid rgb(177, 66, 66);
    font-size: 0;
    //position: relative;
    //z-index: 6;
    img {
      width: 27px;
      vertical-align: middle;
      margin: 0 6px 0 16px;
    }
    span {
      font-size: 14px;
      color: #ffffff;
      vertical-align: middle;
    }
  }
  .addCarSubtitle {
    height: 28px;
    line-height: 28px;
    background-color: #f0f0f0;
    padding-left: 16px;
    font-size: 12px;
    color: #333333;
    margin: 0;
    //position: relative;
    //z-index: 6;
  }
  .addCarAction {
    height: 45px;
    line-height: 45px;
    background-color: #ffffff;
    font-size: 14px;
    font-weight: bold;
    color: #333333;
    padding-left: 16px;
    margin: 0;
  }
  .addCar-list {
    flex: 1 1; //自适应高度需要固定父容器高度，不然会被撑开（这里要设置到最高层父元素高度html,body的高度都为100%）
    height: 0;
    overflow: scroll;
    background-color: #ffffff;
    p {
      font-size: 14px;
      color: #333333;
      height: 50px;
      line-height: 50px;
      margin: 0 0 0 16px;
      list-style: none;
      border-bottom: 0.5px solid #d8d8d8;
    }
  }
}
html,
body {
  height: 100%;
  overflow: hidden;
}
.appcontainer[data-v-ec61c590] {
  padding: 0;
  height: 100%;
}
</style>